#include "assembleDnaTest.h"

using namespace std;

AssembleDnaTest::AssembleDnaTest()
{
}

#define A 0
#define C 1
#define G 2
#define T 3

#define seq(X,Y,Z,T) (char)(T<<6 | Z<<4 | Y<<2 | X)
 
void AssembleDnaTest::setUp()
{
	seq1 = new DnaSeq;
	char tab1[] = {seq(G,A,C,T)};
	fillDnaSeq(seq1, 0, 4, tab1);

	seq2 = new DnaSeq;
	char tab2[] = {seq(A,C,T,G)};
	fillDnaSeq(seq2, 0, 4, tab2);
	
	seq3 = new DnaSeq;
	char tab3[] = {seq(G,A,C,T), seq(A,0,0,0)};               
	fillDnaSeq(seq3, 0, 5, tab3);
	
	seq4 = new DnaSeq;
	char tab4[] = {seq(G,G,A,C), seq(T,0,0,0)};               
	fillDnaSeq(seq4, 0, 5, tab4);
	
	seq5 = new DnaSeq;
	char tab5[] = {seq(G,A,C,T), seq(G,A,C,T), seq(G,A,C,T), seq(A,0,0,0)};               
	fillDnaSeq(seq5, 0, 13, tab5);
	
	seq6 = new DnaSeq;
	char tab6[] = {seq(A,C,T,G), seq(A,C,T,G), seq(A,C,T,A), seq(T,0,0,0)};               
	fillDnaSeq(seq6, 0, 13, tab6);
	
}

void AssembleDnaTest::testAssemble()
{
	// GACT + ACTG => GACTG
	string ref1 = "GACTG";
	DnaSeq * seqRes1 = new DnaSeq;
	CPPUNIT_ASSERT( assembleDna(seq1, seq2, seqRes1) == true );
	string res1;
	conv2string(*seqRes1, res1);
	CPPUNIT_ASSERT( strcmp(res1.c_str(), ref1.c_str()) == 0 );
	CPPUNIT_ASSERT( seq1->flag == seq2->flag == 1 );
	CPPUNIT_ASSERT( seqRes1->len == seq1->len +1 );
	
	// GACT + GACTA => GACTA
	string ref2 = "GACTA";
	DnaSeq * seqRes2 = new DnaSeq;
	CPPUNIT_ASSERT( assembleDna(seq1, seq3, seqRes2) == true );
	string res2;
	conv2string(*seqRes2, res2);
	CPPUNIT_ASSERT( strcmp(res2.c_str(), ref2.c_str()) == 0 );
	CPPUNIT_ASSERT( seq1->flag == seq3->flag == 1 );
	CPPUNIT_ASSERT( seqRes2->len == seq1->len +1 );
	
	// GACT + GGACT => pas d'assemblage
	CPPUNIT_ASSERT( assembleDna(seq1, seq4, seqRes2) == false );
	
	// GACT GACT GACT A + ACTG ACTG ACTA T => GACT GACT GACT AT
	string ref3 = "GACTGACTGACTAT";
	DnaSeq * seqRes3 = new DnaSeq;
	CPPUNIT_ASSERT( assembleDna(seq5, seq6, seqRes3) == true );
	string res3;
	conv2string(*seqRes3, res3);
	CPPUNIT_ASSERT( strcmp(res3.c_str(), ref3.c_str()) == 0 );
	CPPUNIT_ASSERT( seq5->flag == seq6->flag == 1 );
	CPPUNIT_ASSERT( seqRes3->len == seq5->len +1 );
	
}


void AssembleDnaTest::tearDown()
{
	delete(seq1);
	delete(seq2);
	delete(seq3);
	delete(seq4);
	delete(seq5);
	delete(seq6);
}

